<?php
include "header.php";
include "mysqli_connection.php";

if (!isset($_SESSION["username"])){
	echo "<script>window.location.href='login.php'</script>";
}
else{
?>
<script>change_picture("admin");</script>
<script>
function jump(){
	window.location.href='manageprograms.php';
}
window.setTimeout("jump();",3000);
</script>
<div>
<?php
	if (isset($_POST["id"]) && $_POST["id"] !== ""){
		$p_id = $mysqli->real_escape_string(trim($_POST["id"]));
		if ($p_id != 0){
			$query = "DELETE FROM Programs WHERE p_id = ?;";
			$stmt = $mysqli->stmt_init();
			if ($stmt = $mysqli->prepare($query)){
				$stmt->bind_param("i", $p_id);
				if (!$stmt->execute()){
					$stmt->close();
					echo "Delete failed! ";
				}
				else{
					$stmt->close();
					$query = "DELETE FROM Requirement_Program WHERE p_id = ?;";
					$stmt = $mysqli->stmt_init();
					if ($stmt = $mysqli->prepare($query)){
						$stmt->bind_param("i", $p_id);
						if (!$stmt->execute()){
							echo "Update failed! ";
						}
						else{
							echo "Delete Succeed! ";
						}
						$stmt->close();
					}
				}
			}
		}
		else{
		
		}
	}
	else{
	
	}
?>
Jumping to manage courses page in 3 seconds...<br />
<a href="manageprograms.php">Click here to jump immediately</a>
</div>
<?php
}
include "footer.php";